﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>{{PageTitle}}</title>
</head>
<body>
    <script type="text/javascript">
        function AddMenu(FID) {
            $.post("~/Admin/System/SaveMenu", { FID: FID, MenuName: $('#MenuName').val(), MenuUrl: $('#MenuUrl').val() });
            $('#win').window('close');
            $('#MenuList').treegrid('reload');

        }


        function addMenu() {
            var node = $('#MenuList').treegrid('getSelected');
            if (node) {
                $('#win').window('open');
                $('#MenuFID').val(node.MenuName);
                $('#MenuFID').attr("value", node.ID);
            } else {
                $('#win').window('open');
                $('#MenuFID').val('第一级菜单');
                $('#MenuFID').attr("value", 0);
            }
        }
        function editMenu() {
            var node = $('#MenuList').treegrid('getSelected');
            if (node) {
                $('#MenuList').treegrid('beginEdit', node.ID);
            }
        }
        function saveMenu() {
            var node = $('#MenuList').treegrid('getSelected');
            if (node) {
                $('#MenuList').treegrid('endEdit', node.ID);
                $.post("~/Admin/System/SaveMenu", { ID: node.ID, FID: node.FID, MenuName: node.MenuName, MenuUrl: node.MenuUrl });
                $('#MenuList').treegrid('reload');
            }
        }
        function delteMenu() 
        {
            var node = $('#MenuList').treegrid('getSelected');
            if (node) {
                $.post("~/Admin/System/DelMenu", { ID: node.ID }, function (result) { alert(result)});
            }
            cancelMenu();
        }
        function cancelMenu() {
            $('#MenuList').treegrid('reload');
        }
    </script>
    <table id="MenuList" class="easyui-treegrid" url="~/Admin/System/GetMenuList" pagesize="20"
        pagination="true" singleselect="true" toolbar="#tools" idfield="ID" treefield="MenuName">
        <thead>
            <tr>
                <th field="ID" rowspan="2" width="60">
                    菜单编号
                </th>
                <th field="FID" rowspan="2" width="60">
                    上级编号
                </th>
                <th field="MenuName" width="200" editor="text">
                    菜单名称
                </th>
                <th field="MenuUrl" width="300" editor="text">
                    菜单地址
                </th>
            </tr>
        </thead>
    </table>
    <div id="tools">
        <a href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="addMenu()">
            增加</a><a href="#" class="easyui-linkbutton" iconcls="icon-save" plain="true" onclick="saveMenu()">
                保存</a> <a href="#" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editMenu()">
                    修改</a> <a href="#" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="delteMenu()">
                        删除</a> <a href="#" class="easyui-linkbutton" iconcls="icon-undo" plain="true" onclick="cancelMenu()">
                            撤销</a>
    </div>
    <div id="win" class="easyui-window" closed="true" modal="true" iconcls="icon-save"
        title="添加菜单" style="width: 300px; height: 200px; padding: 5px;">
        <div>
            <label for="name">
                上级菜单:</label>
            <input disabled="disabled" type="text" id="MenuFID" name="FID"></input>
        </div>
        <div>
            <label for="email">
                菜单名称:</label>
            <input class="easyui-validatebox" type="text" name="MenuName" id="MenuName" required="true"></input>
        </div>
        <div>
            <label for="subject">
                菜单地址:</label>
            <input class="easyui-validatebox" type="text" id="MenuUrl" name="MenuUrl"></input>
        </div>
        <a href="#" class="easyui-linkbutton" iconcls="icon-save" plain="true" onclick="AddMenu($('#MenuFID').attr('value'))">
            保存</a> <a href="#" class="easyui-linkbutton" iconcls="icon-cancel" plain="true" onclick="$('#win').window('close')">
                关闭</a>
    </div>
</body>
</html>
